import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
        path: '/list',
        name: 'List',
        meta: {
            title: '商品列表'
        },
        component: (resolve) => require(['../views/list.vue'], resolve)
    }, {
        path: '/product/:id',
        meta: {
            title: '商品详情'
        },
        component: (resolve) => require(['../views/product.vue'], resolve)
    }, {
        path: '/cart',
        meta: {
            title: '购物车'
        },
        component: (resolve) => require(['../views/cart.vue'], resolve)
    }, {
        path: '*',
        redirect: '/list'
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title;
    next();
})

// router.afterEach((to, from, next) => {
//   window.scrollTo(0, 0);
// })

export default router
